package com.xinqi.modules.sys.feedback.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.FeedbackModeEnum;
import com.xinqi.common.core.enums.FeedbackTypeEnum;
import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.sys.feedback.dto.req.FeedbackGrantDTO;
import com.xinqi.modules.sys.feedback.dto.req.FeedbackQueryDTO;
import com.xinqi.modules.sys.feedback.dto.rsp.FeedbackResultDTO;
import com.xinqi.modules.sys.feedback.service.FeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * ADMIN -- 用户反馈
 *
 * @author: yyzhenn
 * @date: 2023/04/23
 */
@RestController
@RequestMapping("/admin/feedback")
@RequiredArgsConstructor
public class FeedbackAdminController {
    private final FeedbackService feedbackService;

    @Operation(summary = "反馈类型-枚举列表")
    @GetMapping("/type/list")
    public R<List<Map<String, String>>> typeList() {
        return R.data(FeedbackTypeEnum.getSelectList());
    }

    @Operation(summary = "反馈方式-枚举列表")
    @GetMapping("/mode/list")
    public R<List<Map<String, String>>> modeList() {
        return R.data(FeedbackModeEnum.getSelectList());
    }

    @Operation(summary = "用户反馈-分页")
    @GetMapping("/page")
    public R<PageInfo<FeedbackResultDTO>> page(@ParameterObject FeedbackQueryDTO dto) {
        PageInfo<FeedbackResultDTO> page = feedbackService.page(dto, dto);
        return R.data(page);
    }

    @Operation(summary = "用户反馈-详情")
    @GetMapping("/info/{id}")
    public R<FeedbackResultDTO> info(@PathVariable("id") Long id) {
        return R.data(feedbackService.infoByAdminAndId(id));
    }

    @Log(title = ServiceNameConstants.XQ_SYS + " -- 用户反馈奖品发放", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    @Operation(summary = "用户反馈-奖品发放")
    @PostMapping("/grant")
    public R<Boolean> grant(@Validated @RequestBody FeedbackGrantDTO dto) {
        dto.setOperationUserId(LoginHelper.getXqLoginUser().getId());
        return R.data(feedbackService.grantFeedback(dto));
    }

}
